package com.anolesoft.yr.mbus.prod.pack.service.impl;

import com.anolesoft.yr.mbus.prod.model.mapper.ProdServiceMapper;
import com.anolesoft.yr.mbus.prod.model.mapper.ProdServiceValueMapper;
import com.anolesoft.yr.mbus.prod.model.vo.ProdServiceQueryVO;
import com.anolesoft.yr.mbus.prod.model.vo.ProdServiceValueQueryVO;
import com.anolesoft.yr.mbus.prod.pack.dto.*;
import com.anolesoft.yr.mbus.prod.pack.entity.ProdPackage;
import com.anolesoft.yr.mbus.prod.pack.entity.ProdPackageService_;
import com.anolesoft.yr.mbus.prod.pack.mapper.ProdPackageMapper;
import com.anolesoft.yr.mbus.prod.pack.mapper.ProdPackageRelMapper;
import com.anolesoft.yr.mbus.prod.pack.mapper.ProdPackageServiceMapper;
import com.anolesoft.yr.mbus.prod.pack.mapper.ProdPackageServiceValueMapper;
import com.anolesoft.yr.mbus.prod.pack.service.ProdPackageService;
import com.anolesoft.yr.mbus.prod.pack.vo.ProdPackageQueryVO;
import com.anolesoft.yr.mbus.prod.pack.vo.ProdPackageServiceQueryVO;
import com.anolesoft.yr.mbus.prod.pack.vo.ProdPackageServiceQueryVO2;
import com.anolesoft.yr.mbus.prod.pack.vo.ProdPackageServiceValueQueryVO;
import com.anolesoft.yr.mbus.util.GlobalLoginInfo;
import com.anolesoft.yr.mbus.util.StrCP;
import com.anolesoft.yr.mbus.util.VersionController;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

@Service
public class ProdPackageServiceImpl implements ProdPackageService {

    private static final String CODE_EXIST = "CODE_EXIST";
    private static final String NAME_EXIST = "NAME_EXIST";
    private static final String SUCCESS = "SUCCESS";
    private static final String EXCEPTION = "EXCEPTION";

    @Autowired
    ProdPackageMapper prodPackageMapper;
    @Autowired
    ProdPackageRelMapper prodPackageRelMapper;
    @Autowired
    ProdPackageServiceMapper prodPackageServiceMapper;
    @Autowired
    ProdPackageServiceValueMapper prodPackageServiceValueMapper;
    @Autowired
    ProdServiceMapper prodServiceMapper;
    @Autowired
    ProdServiceValueMapper prodServiceValueMapper;

    //新增产品套餐信息表
    @Override
    @Transactional
    public String saveProdPackage(ProdPackageSaveDTO prodPackageSaveDTO) throws Exception {
        try {
            int count = 0;
            count = prodPackageMapper.queryProdPackageByCode(prodPackageSaveDTO.getSpeciesCode());
            if (count > 0) {
                return CODE_EXIST;
            }

            count = prodPackageMapper.queryProdPackageByName(prodPackageSaveDTO.getSpeciesName());
            if (count > 0) {
                return NAME_EXIST;
            }

            List prodPackageRelSaveDTOList = prodPackageSaveDTO.getProdPackageRelSaveDTO();
            List prodPackageServiceSaveDTOList = prodPackageSaveDTO.getProdPackageServiceSaveDTO();

            for (int i = 0; i < prodPackageRelSaveDTOList.size(); i++) {
                ProdPackageRelSaveDTO prodPackageRelSaveDTO = (ProdPackageRelSaveDTO) prodPackageRelSaveDTOList.get(i);
                prodPackageRelMapper.saveProdPackageRel(prodPackageRelSaveDTO);
            }

            for (int i = 0; i < prodPackageServiceSaveDTOList.size(); i++) {
                ProdPackageServiceSaveDTO prodPackageServiceSaveDTO = (ProdPackageServiceSaveDTO) prodPackageServiceSaveDTOList.get(i);

                ProdServiceQueryVO prodServiceQueryVO = prodServiceMapper.queryProdServiceByUid3(prodPackageServiceSaveDTO.getProdServiceUid());
                prodPackageServiceSaveDTO.setServiceOptionCode(prodServiceQueryVO.getUpdateServiceCode());
                prodPackageServiceSaveDTO.setServiceOptionName(prodServiceQueryVO.getUpdateServiceName());
                prodPackageServiceSaveDTO.setImportType(prodServiceQueryVO.getUpdateImportType());

                prodPackageServiceMapper.saveProdPackageService(prodPackageServiceSaveDTO);

                List prodPackageServiceValueSaveDTOList = prodPackageServiceSaveDTO.getProdPackageServiceValueSaveDTO();
                for (int j = 0; j < prodPackageServiceValueSaveDTOList.size(); j++) {
                    ProdPackageServiceValueSaveDTO prodPackageServiceValueSaveDTO = (ProdPackageServiceValueSaveDTO) prodPackageServiceValueSaveDTOList.get(j);

                    ProdServiceValueQueryVO prodServiceValueQueryVO = prodServiceValueMapper.queryProdServiceValueByUid4(prodPackageServiceValueSaveDTO.getProdServiceValueUid());
                    prodPackageServiceValueSaveDTO.setValue(prodServiceValueQueryVO.getUpdateValue());
                    prodPackageServiceValueSaveDTO.setIsDefault(new Integer(prodServiceValueQueryVO.getUpdateIsDefault()));
                    prodPackageServiceValueSaveDTO.setIsHoliday(new Integer(prodServiceValueQueryVO.getUpdateIsHoliday()));
                    prodPackageServiceValueSaveDTO.setAcceptTime(prodServiceValueQueryVO.getUpdateAcceptTime());
                    prodPackageServiceValueSaveDTO.setReplyTime(prodServiceValueQueryVO.getUpdateReplyTime());
                    prodPackageServiceValueSaveDTO.setDeliveryTime(prodServiceValueQueryVO.getUpdateDeliveryTime());
                    prodPackageServiceValueSaveDTO.setArrivalTime(prodServiceValueQueryVO.getUpdateArrivalTime());

                    prodPackageServiceValueMapper.saveProdPackageServiceValue(prodPackageServiceValueSaveDTO);
                }
            }

            ProdPackageQueryVO prodPackageQueryVO = prodPackageMapper.queryProdPackageVersionByUid(prodPackageSaveDTO.getProdProductionUid(), prodPackageSaveDTO.getSpeciesName());

            String version = "";
            if (prodPackageQueryVO == null) {
                version = "A";
            } else {
                version = VersionController.getVersion(prodPackageQueryVO.getVersion());
            }

            prodPackageSaveDTO.setVersion(version);
            int rows = prodPackageMapper.saveProdPackage(prodPackageSaveDTO);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //修改产品套餐信息表
    @Override
    @Transactional
    public String updateProdPackage(ProdPackageUpdateDTO prodPackageUpdateDTO) throws Exception {
        try {
            ProdPackage prodPackage = prodPackageMapper.queryProdPackageByUid2(prodPackageUpdateDTO.getObjuid());

            int count = 0;
            count = prodPackageMapper.query2ProdPackageByCode(prodPackageUpdateDTO.getSpeciesCode(), prodPackage.getSpeciesCode());
            if (count > 0) {
                return CODE_EXIST;
            }

            count = prodPackageMapper.query2ProdPackageByName(prodPackageUpdateDTO.getSpeciesName(), prodPackage.getSpeciesName());
            if (count > 0) {
                return NAME_EXIST;
            }

            List prodPackageServiceDeleteDTOList = Lists.newArrayList();
            ProdPackageServiceDeleteDTO prodPackageServiceDeleteDTO = null;
            List prodPackageServiceUpdateDTOList = prodPackageUpdateDTO.getProdPackageServiceSaveDTO();
            for (int i = 0; i < prodPackageServiceUpdateDTOList.size(); i++) {
                ProdPackageServiceUpdateDTO prodPackageServiceUpdateDTO = (ProdPackageServiceUpdateDTO) prodPackageServiceUpdateDTOList.get(i);

                if ("".equals(prodPackageServiceUpdateDTO.getObjuid())) {
                    String prodPackageRelUid = StrCP.createObjuid32(UUID.randomUUID().toString());
                    String prodPackageServicelUid = StrCP.createObjuid32(UUID.randomUUID().toString());

                    ProdPackageRelSaveDTO prodPackageRelSaveDTO = new ProdPackageRelSaveDTO();
                    prodPackageRelSaveDTO.setObjuid(prodPackageRelUid);
                    prodPackageRelSaveDTO.setFacCode("");
                    prodPackageRelSaveDTO.setProdPackageUid(prodPackageUpdateDTO.getObjuid());
                    prodPackageRelSaveDTO.setProdPackageServiceUid(prodPackageServicelUid);
                    prodPackageRelMapper.saveProdPackageRel(prodPackageRelSaveDTO);

                    ProdServiceQueryVO prodServiceQueryVO = prodServiceMapper.queryProdServiceByUid3(prodPackageServiceUpdateDTO.getProdServiceObjuid());
                    ProdPackageServiceSaveDTO prodPackageServiceSaveDTO = new ProdPackageServiceSaveDTO();
                    prodPackageServiceSaveDTO.setObjuid(prodPackageServicelUid);
                    prodPackageServiceSaveDTO.setFacCode("");
                    prodPackageServiceSaveDTO.setProdPackageUid(prodPackageUpdateDTO.getObjuid());
                    prodPackageServiceSaveDTO.setProdServiceUid(prodPackageServiceUpdateDTO.getProdServiceObjuid());
                    prodPackageServiceSaveDTO.setServiceOptionCode(prodServiceQueryVO.getUpdateServiceCode());
                    prodPackageServiceSaveDTO.setServiceOptionName(prodServiceQueryVO.getUpdateServiceName());
                    prodPackageServiceSaveDTO.setImportType(prodServiceQueryVO.getUpdateImportType());

                    prodPackageServiceMapper.saveProdPackageService(prodPackageServiceSaveDTO);

                    List prodPackageServiceValueUpdateDTOList = prodPackageServiceUpdateDTO.getProdPackageServiceValueUpdateDTO();
                    for (int j = 0; j < prodPackageServiceValueUpdateDTOList.size(); j++) {
                        ProdPackageServiceValueUpdateDTO prodPackageServiceValueUpdateDTO = (ProdPackageServiceValueUpdateDTO) prodPackageServiceValueUpdateDTOList.get(j);

                        String prodPackageServiceValuelUid = StrCP.createObjuid32(UUID.randomUUID().toString());

                        ProdServiceValueQueryVO prodServiceValueQueryVO = prodServiceValueMapper.queryProdServiceValueByUid4(prodPackageServiceValueUpdateDTO.getProdServiceValueUid());
                        ProdPackageServiceValueSaveDTO prodPackageServiceValueSaveDTO = new ProdPackageServiceValueSaveDTO();
                        prodPackageServiceValueSaveDTO.setObjuid(prodPackageServiceValuelUid);
                        prodPackageServiceValueSaveDTO.setFacCode("");
                        prodPackageServiceValueSaveDTO.setProdPackageUid(prodPackageUpdateDTO.getObjuid());
                        prodPackageServiceValueSaveDTO.setProdPackageServiceUid(prodPackageServicelUid);
                        prodPackageServiceValueSaveDTO.setProdServiceValueUid(prodPackageServiceValueUpdateDTO.getProdServiceValueUid());
                        prodPackageServiceValueSaveDTO.setValue(prodServiceValueQueryVO.getUpdateValue());
                        prodPackageServiceValueSaveDTO.setIsDefault(new Integer(prodServiceValueQueryVO.getUpdateIsDefault()));
                        prodPackageServiceValueSaveDTO.setIsHoliday(new Integer(prodServiceValueQueryVO.getUpdateIsHoliday()));
                        prodPackageServiceValueSaveDTO.setAcceptTime(prodServiceValueQueryVO.getUpdateAcceptTime());
                        prodPackageServiceValueSaveDTO.setReplyTime(prodServiceValueQueryVO.getUpdateReplyTime());
                        prodPackageServiceValueSaveDTO.setDeliveryTime(prodServiceValueQueryVO.getUpdateDeliveryTime());
                        prodPackageServiceValueSaveDTO.setArrivalTime(prodServiceValueQueryVO.getUpdateArrivalTime());

                        prodPackageServiceValueMapper.saveProdPackageServiceValue(prodPackageServiceValueSaveDTO);
                    }

                    prodPackageServiceDeleteDTO = new ProdPackageServiceDeleteDTO();
                    prodPackageServiceDeleteDTO.setObjuid(prodPackageServicelUid);
                    prodPackageServiceDeleteDTOList.add(prodPackageServiceDeleteDTO);
                } else {
                    ProdServiceQueryVO prodServiceQueryVO = prodServiceMapper.queryProdServiceByUid3(prodPackageServiceUpdateDTO.getProdServiceObjuid());
                    ProdPackageServiceUpdateDTO prodPackageServiceUpdateDTO2 = new ProdPackageServiceUpdateDTO();
                    prodPackageServiceUpdateDTO2.setProdServiceUid(prodPackageServiceUpdateDTO.getProdServiceObjuid());
                    prodPackageServiceUpdateDTO2.setServiceOptionCode(prodServiceQueryVO.getUpdateServiceCode());
                    prodPackageServiceUpdateDTO2.setServiceOptionName(prodServiceQueryVO.getUpdateServiceName());
                    prodPackageServiceUpdateDTO2.setImportType(prodServiceQueryVO.getUpdateImportType());
                    prodPackageServiceUpdateDTO2.setObjuid(prodPackageServiceUpdateDTO.getObjuid());

                    prodPackageServiceMapper.updateProdPackageService(prodPackageServiceUpdateDTO2);

                    List prodPackageServiceValueUpdateDTOList = prodPackageServiceUpdateDTO.getProdPackageServiceValueUpdateDTO();
                    for (int j = 0; j < prodPackageServiceValueUpdateDTOList.size(); j++) {
                        ProdPackageServiceValueUpdateDTO prodPackageServiceValueUpdateDTO = (ProdPackageServiceValueUpdateDTO) prodPackageServiceValueUpdateDTOList.get(j);

                        ProdServiceValueQueryVO prodServiceValueQueryVO = prodServiceValueMapper.queryProdServiceValueByUid4(prodPackageServiceValueUpdateDTO.getProdServiceValueUid());

                        ProdPackageServiceValueUpdateDTO prodPackageServiceValueUpdateDTO2 = new ProdPackageServiceValueUpdateDTO();
                        prodPackageServiceValueUpdateDTO2.setProdServiceValueUid(prodPackageServiceValueUpdateDTO.getProdServiceValueUid());
                        prodPackageServiceValueUpdateDTO2.setValue(prodServiceValueQueryVO.getUpdateValue());
                        prodPackageServiceValueUpdateDTO2.setIsDefault(new Integer(prodServiceValueQueryVO.getUpdateIsDefault()));
                        prodPackageServiceValueUpdateDTO2.setIsHoliday(new Integer(prodServiceValueQueryVO.getUpdateIsHoliday()));
                        prodPackageServiceValueUpdateDTO2.setAcceptTime(prodServiceValueQueryVO.getUpdateAcceptTime());
                        prodPackageServiceValueUpdateDTO2.setReplyTime(prodServiceValueQueryVO.getUpdateReplyTime());
                        prodPackageServiceValueUpdateDTO2.setDeliveryTime(prodServiceValueQueryVO.getUpdateDeliveryTime());
                        prodPackageServiceValueUpdateDTO2.setArrivalTime(prodServiceValueQueryVO.getUpdateArrivalTime());
                        prodPackageServiceValueUpdateDTO2.setObjuid(prodPackageServiceValueUpdateDTO.getObjuid());

                        prodPackageServiceValueMapper.updateProdPackageServiceValue(prodPackageServiceValueUpdateDTO2);
                    }

                    prodPackageServiceDeleteDTO = new ProdPackageServiceDeleteDTO();
                    prodPackageServiceDeleteDTO.setObjuid(prodPackageServiceUpdateDTO.getObjuid());
                    prodPackageServiceDeleteDTOList.add(prodPackageServiceDeleteDTO);
                }
            }

            prodPackageServiceValueMapper.deleteProdPackageServiceValue(prodPackageUpdateDTO.getObjuid(), prodPackageServiceDeleteDTOList);
            prodPackageServiceMapper.deleteProdPackageService(prodPackageUpdateDTO.getObjuid(), prodPackageServiceDeleteDTOList);
            prodPackageRelMapper.deleteProdPackageRel(prodPackageUpdateDTO.getObjuid(), prodPackageServiceDeleteDTOList);

            int rows = prodPackageMapper.updateProdPackage(prodPackageUpdateDTO);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //提交产品套餐信息表
    @Override
    @Transactional
    public String submitProdPackage(List<ProdPackageUpdateDTO> ProdPackageUpdateDTOList) throws Exception {
        try {
            int rows = 0;
            for (int i = 0; i < ProdPackageUpdateDTOList.size(); i++) {
                ProdPackageUpdateDTO prodPackageUpdateDTO = ProdPackageUpdateDTOList.get(i);
                rows += prodPackageMapper.submitProdPackage(prodPackageUpdateDTO);
            }

            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //审批通过产品套餐信息表
    @Override
    @Transactional
    public String passProdPackage(List<ProdPackageUpdateDTO> ProdPackageUpdateDTOList) throws Exception {
        try {
            int rows = 0;
            for (int i = 0; i < ProdPackageUpdateDTOList.size(); i++) {
                ProdPackageUpdateDTO prodPackageUpdateDTO = ProdPackageUpdateDTOList.get(i);
                rows += prodPackageMapper.passProdPackage(prodPackageUpdateDTO);
            }

            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //审批驳回产品套餐信息表
    @Override
    @Transactional
    public String rejectProdPackage(ProdPackage prodPackage) throws Exception {
        try {
            int rows = 0;
            List prodPackageServiceList = prodPackage.getProdPackageService_();
            for (int i = 0; i < prodPackageServiceList.size(); i++) {
                ProdPackageService_ prodPackageService_ = (ProdPackageService_) prodPackageServiceList.get(i);
                rows += prodPackageMapper.rejectProdPackage(prodPackageService_);

                String rejectReason = prodPackage.getRejectReason();
                System.out.println("这里需要向工单表中写入数据，把驳回原因回写到工单指定表中......");
                System.out.println("回写的业务表主键：" + prodPackageService_.getObjuid() + "，回写的原因：" + rejectReason);
            }

            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //设置产品套餐信息表
    @Override
    @Transactional
    public String setTimeProdPackage(ProdPackageUpdateDTO prodPackageUpdateDTO) throws Exception {
        try {
            int rows = prodPackageMapper.setTimeProdPackage(prodPackageUpdateDTO);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //升版产品套餐信息表
    @Override
    @Transactional
    public String upVersionProdPackage(ProdPackageUpdateDTO prodPackageUpdateDTO) throws Exception {
        try {
            ProdPackage prodPackage = prodPackageMapper.queryProdPackageByUid2(prodPackageUpdateDTO.getObjuid());
            ProdPackage prodPackage_ = prodPackageMapper.queryProdPackageByUid3(prodPackageUpdateDTO.getObjuid());

            String prodPackageUid = StrCP.createObjuid32(UUID.randomUUID().toString());
            ProdPackageSaveDTO prodPackageSaveDTO = new ProdPackageSaveDTO();
            prodPackageSaveDTO.setObjuid(prodPackageUid);
            prodPackageSaveDTO.setFacCode("");
            prodPackageSaveDTO.setProdProductionUid(prodPackage.getProdProductionUid());
            prodPackageSaveDTO.setSpeciesCode(prodPackage.getSpeciesCode());
            prodPackageSaveDTO.setSpeciesName(prodPackage.getSpeciesName());
            prodPackageSaveDTO.setSpeciesDescribe(prodPackage.getSpeciesDescribe());
            prodPackageSaveDTO.setSpeciesApprovalState(0);
            prodPackageSaveDTO.setIsSetup(0);
            prodPackageSaveDTO.setVersion(VersionController.getVersion(prodPackage_.getVersion()));
            prodPackageSaveDTO.setRemark(prodPackage.getRemark());
            prodPackageSaveDTO.setCcUserUid(GlobalLoginInfo.getGlobalLoginUser());
            prodPackageSaveDTO.setCcTime(GlobalLoginInfo.getGlobalLoginTime());
            prodPackageSaveDTO.setDelFlag(0);

            List<ProdPackageServiceQueryVO2> prodPackageServiceQueryVOList = prodPackageServiceMapper.queryProdPackageServiceByUid2(prodPackageUpdateDTO.getObjuid());
            for (int i = 0; i < prodPackageServiceQueryVOList.size(); i++) {
                ProdPackageServiceQueryVO2 prodPackageServiceQueryVO2 = prodPackageServiceQueryVOList.get(i);

                String prodPackageRellUid = StrCP.createObjuid32(UUID.randomUUID().toString());
                String prodPackageServiceUid = StrCP.createObjuid32(UUID.randomUUID().toString());
                ProdPackageRelSaveDTO prodPackageRelSaveDTO = new ProdPackageRelSaveDTO();
                prodPackageRelSaveDTO.setObjuid(prodPackageRellUid);
                prodPackageRelSaveDTO.setFacCode("");
                prodPackageRelSaveDTO.setProdPackageUid(prodPackageUid);
                prodPackageRelSaveDTO.setProdPackageServiceUid(prodPackageServiceUid);
                prodPackageRelMapper.saveProdPackageRel(prodPackageRelSaveDTO);

                ProdPackageServiceSaveDTO prodPackageServiceSaveDTO = new ProdPackageServiceSaveDTO();
                prodPackageServiceSaveDTO.setObjuid(prodPackageServiceUid);
                prodPackageServiceSaveDTO.setFacCode("");
                prodPackageServiceSaveDTO.setProdPackageUid(prodPackageUid);
                prodPackageServiceSaveDTO.setProdServiceUid(prodPackageServiceQueryVO2.getProdServiceUid());
                prodPackageServiceSaveDTO.setServiceOptionCode(prodPackageServiceQueryVO2.getServiceOptionCode());
                prodPackageServiceSaveDTO.setServiceOptionName(prodPackageServiceQueryVO2.getServiceOptionName());
                prodPackageServiceSaveDTO.setImportType(prodPackageServiceQueryVO2.getImportType());
                prodPackageServiceMapper.saveProdPackageService(prodPackageServiceSaveDTO);

                List<ProdPackageServiceValueQueryVO> prodPackageServiceValueQueryVOList = prodPackageServiceValueMapper.queryProdPackageServiceValueByUid(prodPackageUpdateDTO.getObjuid(), prodPackageServiceQueryVO2.getObjuid());
                for (int j = 0; j < prodPackageServiceValueQueryVOList.size(); j++) {
                    ProdPackageServiceValueQueryVO prodPackageServiceValueQueryVO = prodPackageServiceValueQueryVOList.get(j);

                    String prodPackageServiceValueUid = StrCP.createObjuid32(UUID.randomUUID().toString());
                    ProdPackageServiceValueSaveDTO prodPackageServiceValueSaveDTO = new ProdPackageServiceValueSaveDTO();
                    prodPackageServiceValueSaveDTO.setObjuid(prodPackageServiceValueUid);
                    prodPackageServiceValueSaveDTO.setFacCode("");
                    prodPackageServiceValueSaveDTO.setProdPackageUid(prodPackageUid);
                    prodPackageServiceValueSaveDTO.setProdPackageServiceUid(prodPackageServiceUid);
                    prodPackageServiceValueSaveDTO.setProdServiceValueUid(prodPackageServiceValueQueryVO.getProdServiceValueUid());
                    prodPackageServiceValueSaveDTO.setValue(prodPackageServiceValueQueryVO.getValue());
                    prodPackageServiceValueSaveDTO.setIsDefault(prodPackageServiceValueQueryVO.getIsDefault());
                    prodPackageServiceValueSaveDTO.setIsHoliday(prodPackageServiceValueQueryVO.getIsHoliday());
                    prodPackageServiceValueSaveDTO.setAcceptTime(prodPackageServiceValueQueryVO.getAcceptTime());
                    prodPackageServiceValueSaveDTO.setReplyTime(prodPackageServiceValueQueryVO.getReplyTime());
                    prodPackageServiceValueSaveDTO.setDeliveryTime(prodPackageServiceValueQueryVO.getDeliveryTime());
                    prodPackageServiceValueSaveDTO.setArrivalTime(prodPackageServiceValueQueryVO.getArrivalTime());

                    prodPackageServiceValueMapper.saveProdPackageServiceValue(prodPackageServiceValueSaveDTO);
                }
            }

            int rows = prodPackageMapper.saveProdPackage(prodPackageSaveDTO);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //删除产品套餐信息表
    @Override
    @Transactional
    public String deleteProdPackage(List<ProdPackageDeleteDTO> ProdPackageDeleteDTOList) throws Exception {
        try {
            int rows = 0;
            for (int i = 0; i < ProdPackageDeleteDTOList.size(); i++) {
                ProdPackageDeleteDTO prodPackageDeleteDTO = ProdPackageDeleteDTOList.get(i);
                rows += prodPackageMapper.deleteProdPackage(prodPackageDeleteDTO);
            }

            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            throw new TimeoutException(EXCEPTION);
        }
    }

    //根据主键查询产品服务项及参数数据
    @Override
    public Map<String, Object> queryProdPackageByUid(String uid) throws Exception {
        ProdPackageQueryVO prodPackageQueryVO = prodPackageMapper.queryProdPackageByUid(uid);
        List<ProdPackageServiceQueryVO> ProdPackageServiceQueryVOList = prodPackageServiceMapper.queryProdPackageServiceByUid(uid);

        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("prodPackageQueryVO", prodPackageQueryVO);
        maps.put("ProdPackageServiceQueryVOList", ProdPackageServiceQueryVOList);

        return maps;
    }

    //根据条件查询产品套餐所有数据
    @Override
    public Map<String, Object> queryProdPackageAll(String typeName, String prodName, String speciesName, String speciesApprovalState, int page, int limit) throws Exception {
        int count = prodPackageMapper.queryProdPackageAllCount(typeName, prodName, speciesName, speciesApprovalState);
        List<ProdPackageQueryVO> prodPackageQueryVOList = prodPackageMapper.queryProdPackageAll(typeName, prodName, speciesName, speciesApprovalState, (page - 1) * limit, limit);

        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("count", count);
        maps.put("prodPackageQueryVOList", prodPackageQueryVOList);
        return maps;
    }

    //根据条件查询产品套餐设置所有数据
    @Override
    public Map<String, Object> queryProdPackageSetTimeAll(String typeName, String prodName, String speciesName, int page, int limit) throws Exception {
        int count = prodPackageMapper.queryProdPackageSetTimeAllCount(typeName, prodName, speciesName);
        List<ProdPackageQueryVO> prodPackageQueryVOList = prodPackageMapper.queryProdPackageSetTimeAll(typeName, prodName, speciesName, (page - 1) * limit, limit);

        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("count", count);
        maps.put("prodPackageQueryVOList", prodPackageQueryVOList);
        return maps;
    }

    //根据条件查询产品套餐审批所有数据
    @Override
    public Map<String, Object> queryProdPackageApproveAll(String typeName, String prodName, String speciesName, int page, int limit) throws Exception {
        int count = prodPackageMapper.queryProdPackageApproveAllCount(typeName, prodName, speciesName);
        List<ProdPackageQueryVO> prodPackageQueryVOList = prodPackageMapper.queryProdPackageApproveAll(typeName, prodName, speciesName, (page - 1) * limit, limit);

        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("count", count);
        maps.put("prodPackageQueryVOList", prodPackageQueryVOList);
        return maps;
    }

    //根据条件查询产品套餐名称
    @Override
    public List<ProdPackageQueryVO> queryProdPackageName(String prodName) throws Exception {
        List<ProdPackageQueryVO> prodPackageQueryVOList = prodPackageMapper.queryProdPackageName(prodName);
        return prodPackageQueryVOList;
    }

    //根据条件查询产品套餐服务项及参数
    @Override
    public List<ProdPackageQueryVO> queryProdPackageServiceNameValue(String speciesName) throws Exception {
        List<ProdPackageQueryVO> prodPackageQueryVOList = prodPackageMapper.queryProdPackageServiceNameValue(speciesName);
        return prodPackageQueryVOList;
    }

}
